package com.qingke.oms.factory;

import java.util.HashMap;
import java.util.Map;

import com.qingke.oms.command.Command;
import com.qingke.oms.command.system.ExitCommand;
import com.qingke.oms.command.system.HelpSystemCommand;
import com.qingke.oms.command.system.LoginCommand;
import com.qingke.oms.command.system.RegisterCommand;

public class SystemCommandFactory extends CommandFactory{
	private static Map<CommandCode,Class<? extends Command>> systemMap=new HashMap<>();
	
	static{
		systemMap.put(CommandCode.LOGIN, LoginCommand.class);
		systemMap.put(CommandCode.REGISTER, RegisterCommand.class);
		systemMap.put(CommandCode.HELP, HelpSystemCommand.class);
		systemMap.put(CommandCode.EXIT, ExitCommand.class);
	}
	
	@Override
	public Command buildCommand(CommandCode cmdCode) {
		Class<? extends Command> commandClass=systemMap.get(cmdCode);
		
		if(commandClass==null)
			return null;
		
		Command command=null;
		try {
			command = commandClass.newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return command;
	}

}
